using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the Type class.
	/// </summary>
    [Serializable]
	public partial class TypeCollection : ActiveList<Type, TypeCollection>
	{	   
		public TypeCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>TypeCollection</returns>
		public TypeCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Type o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Type table.
	/// </summary>
	[Serializable]
	public partial class Type : ActiveRecord<Type>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Type()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Type(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Type(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Type(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Type", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarTypeId = new TableSchema.TableColumn(schema);
				colvarTypeId.ColumnName = "TypeId";
				colvarTypeId.DataType = DbType.Guid;
				colvarTypeId.MaxLength = 0;
				colvarTypeId.AutoIncrement = false;
				colvarTypeId.IsNullable = false;
				colvarTypeId.IsPrimaryKey = true;
				colvarTypeId.IsForeignKey = false;
				colvarTypeId.IsReadOnly = false;
				
						colvarTypeId.DefaultSetting = @"(newid())";
				colvarTypeId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTypeId);
				
				TableSchema.TableColumn colvarParentTypeId = new TableSchema.TableColumn(schema);
				colvarParentTypeId.ColumnName = "ParentTypeId";
				colvarParentTypeId.DataType = DbType.Guid;
				colvarParentTypeId.MaxLength = 0;
				colvarParentTypeId.AutoIncrement = false;
				colvarParentTypeId.IsNullable = true;
				colvarParentTypeId.IsPrimaryKey = false;
				colvarParentTypeId.IsForeignKey = true;
				colvarParentTypeId.IsReadOnly = false;
				colvarParentTypeId.DefaultSetting = @"";
				
					colvarParentTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarParentTypeId);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 50;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = false;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				colvarName.DefaultSetting = @"";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarCanHaveChilds = new TableSchema.TableColumn(schema);
				colvarCanHaveChilds.ColumnName = "CanHaveChilds";
				colvarCanHaveChilds.DataType = DbType.Boolean;
				colvarCanHaveChilds.MaxLength = 0;
				colvarCanHaveChilds.AutoIncrement = false;
				colvarCanHaveChilds.IsNullable = false;
				colvarCanHaveChilds.IsPrimaryKey = false;
				colvarCanHaveChilds.IsForeignKey = false;
				colvarCanHaveChilds.IsReadOnly = false;
				
						colvarCanHaveChilds.DefaultSetting = @"((1))";
				colvarCanHaveChilds.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCanHaveChilds);
				
				TableSchema.TableColumn colvarIsGenerated = new TableSchema.TableColumn(schema);
				colvarIsGenerated.ColumnName = "IsGenerated";
				colvarIsGenerated.DataType = DbType.Boolean;
				colvarIsGenerated.MaxLength = 0;
				colvarIsGenerated.AutoIncrement = false;
				colvarIsGenerated.IsNullable = false;
				colvarIsGenerated.IsPrimaryKey = false;
				colvarIsGenerated.IsForeignKey = false;
				colvarIsGenerated.IsReadOnly = false;
				
						colvarIsGenerated.DefaultSetting = @"((1))";
				colvarIsGenerated.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsGenerated);
				
				TableSchema.TableColumn colvarIsManyToMany = new TableSchema.TableColumn(schema);
				colvarIsManyToMany.ColumnName = "IsManyToMany";
				colvarIsManyToMany.DataType = DbType.Boolean;
				colvarIsManyToMany.MaxLength = 0;
				colvarIsManyToMany.AutoIncrement = false;
				colvarIsManyToMany.IsNullable = false;
				colvarIsManyToMany.IsPrimaryKey = false;
				colvarIsManyToMany.IsForeignKey = false;
				colvarIsManyToMany.IsReadOnly = false;
				
						colvarIsManyToMany.DefaultSetting = @"((0))";
				colvarIsManyToMany.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsManyToMany);
				
				TableSchema.TableColumn colvarPath = new TableSchema.TableColumn(schema);
				colvarPath.ColumnName = "Path";
				colvarPath.DataType = DbType.AnsiString;
				colvarPath.MaxLength = 500;
				colvarPath.AutoIncrement = false;
				colvarPath.IsNullable = false;
				colvarPath.IsPrimaryKey = false;
				colvarPath.IsForeignKey = false;
				colvarPath.IsReadOnly = false;
				colvarPath.DefaultSetting = @"";
				colvarPath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPath);
				
				TableSchema.TableColumn colvarDepth = new TableSchema.TableColumn(schema);
				colvarDepth.ColumnName = "Depth";
				colvarDepth.DataType = DbType.Int32;
				colvarDepth.MaxLength = 0;
				colvarDepth.AutoIncrement = false;
				colvarDepth.IsNullable = false;
				colvarDepth.IsPrimaryKey = false;
				colvarDepth.IsForeignKey = false;
				colvarDepth.IsReadOnly = false;
				colvarDepth.DefaultSetting = @"";
				colvarDepth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDepth);
				
				TableSchema.TableColumn colvarRoles = new TableSchema.TableColumn(schema);
				colvarRoles.ColumnName = "Roles";
				colvarRoles.DataType = DbType.String;
				colvarRoles.MaxLength = -1;
				colvarRoles.AutoIncrement = false;
				colvarRoles.IsNullable = true;
				colvarRoles.IsPrimaryKey = false;
				colvarRoles.IsForeignKey = false;
				colvarRoles.IsReadOnly = false;
				colvarRoles.DefaultSetting = @"";
				colvarRoles.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRoles);
				
				TableSchema.TableColumn colvarFlags = new TableSchema.TableColumn(schema);
				colvarFlags.ColumnName = "Flags";
				colvarFlags.DataType = DbType.Int32;
				colvarFlags.MaxLength = 0;
				colvarFlags.AutoIncrement = false;
				colvarFlags.IsNullable = false;
				colvarFlags.IsPrimaryKey = false;
				colvarFlags.IsForeignKey = false;
				colvarFlags.IsReadOnly = false;
				colvarFlags.DefaultSetting = @"";
				colvarFlags.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFlags);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = -1;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				colvarDescription.DefaultSetting = @"";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarExtendedProperties = new TableSchema.TableColumn(schema);
				colvarExtendedProperties.ColumnName = "ExtendedProperties";
				colvarExtendedProperties.DataType = DbType.AnsiString;
				colvarExtendedProperties.MaxLength = -1;
				colvarExtendedProperties.AutoIncrement = false;
				colvarExtendedProperties.IsNullable = true;
				colvarExtendedProperties.IsPrimaryKey = false;
				colvarExtendedProperties.IsForeignKey = false;
				colvarExtendedProperties.IsReadOnly = false;
				colvarExtendedProperties.DefaultSetting = @"";
				colvarExtendedProperties.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExtendedProperties);
				
				TableSchema.TableColumn colvarIsSystem = new TableSchema.TableColumn(schema);
				colvarIsSystem.ColumnName = "IsSystem";
				colvarIsSystem.DataType = DbType.Boolean;
				colvarIsSystem.MaxLength = 0;
				colvarIsSystem.AutoIncrement = false;
				colvarIsSystem.IsNullable = false;
				colvarIsSystem.IsPrimaryKey = false;
				colvarIsSystem.IsForeignKey = false;
				colvarIsSystem.IsReadOnly = false;
				
						colvarIsSystem.DefaultSetting = @"((0))";
				colvarIsSystem.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsSystem);
				
				TableSchema.TableColumn colvarIsAbstract = new TableSchema.TableColumn(schema);
				colvarIsAbstract.ColumnName = "IsAbstract";
				colvarIsAbstract.DataType = DbType.Boolean;
				colvarIsAbstract.MaxLength = 0;
				colvarIsAbstract.AutoIncrement = false;
				colvarIsAbstract.IsNullable = false;
				colvarIsAbstract.IsPrimaryKey = false;
				colvarIsAbstract.IsForeignKey = false;
				colvarIsAbstract.IsReadOnly = false;
				
						colvarIsAbstract.DefaultSetting = @"((0))";
				colvarIsAbstract.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsAbstract);
				
				TableSchema.TableColumn colvarIsVersioned = new TableSchema.TableColumn(schema);
				colvarIsVersioned.ColumnName = "IsVersioned";
				colvarIsVersioned.DataType = DbType.Boolean;
				colvarIsVersioned.MaxLength = 0;
				colvarIsVersioned.AutoIncrement = false;
				colvarIsVersioned.IsNullable = false;
				colvarIsVersioned.IsPrimaryKey = false;
				colvarIsVersioned.IsForeignKey = false;
				colvarIsVersioned.IsReadOnly = false;
				
						colvarIsVersioned.DefaultSetting = @"((1))";
				colvarIsVersioned.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsVersioned);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				
						colvarIsDeleted.DefaultSetting = @"((0))";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				TableSchema.TableColumn colvarIsAdmin = new TableSchema.TableColumn(schema);
				colvarIsAdmin.ColumnName = "IsAdmin";
				colvarIsAdmin.DataType = DbType.Boolean;
				colvarIsAdmin.MaxLength = 0;
				colvarIsAdmin.AutoIncrement = false;
				colvarIsAdmin.IsNullable = false;
				colvarIsAdmin.IsPrimaryKey = false;
				colvarIsAdmin.IsForeignKey = false;
				colvarIsAdmin.IsReadOnly = false;
				
						colvarIsAdmin.DefaultSetting = @"((1))";
				colvarIsAdmin.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsAdmin);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Type",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("TypeId")]
		[Bindable(true)]
		public Guid TypeId 
		{
			get { return GetColumnValue<Guid>(Columns.TypeId); }
			set { SetColumnValue(Columns.TypeId, value); }
		}
		  
		[XmlAttribute("ParentTypeId")]
		[Bindable(true)]
		public Guid? ParentTypeId 
		{
			get { return GetColumnValue<Guid?>(Columns.ParentTypeId); }
			set { SetColumnValue(Columns.ParentTypeId, value); }
		}
		  
		[XmlAttribute("Name")]
		[Bindable(true)]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }
			set { SetColumnValue(Columns.Name, value); }
		}
		  
		[XmlAttribute("CanHaveChilds")]
		[Bindable(true)]
		public bool CanHaveChilds 
		{
			get { return GetColumnValue<bool>(Columns.CanHaveChilds); }
			set { SetColumnValue(Columns.CanHaveChilds, value); }
		}
		  
		[XmlAttribute("IsGenerated")]
		[Bindable(true)]
		public bool IsGenerated 
		{
			get { return GetColumnValue<bool>(Columns.IsGenerated); }
			set { SetColumnValue(Columns.IsGenerated, value); }
		}
		  
		[XmlAttribute("IsManyToMany")]
		[Bindable(true)]
		public bool IsManyToMany 
		{
			get { return GetColumnValue<bool>(Columns.IsManyToMany); }
			set { SetColumnValue(Columns.IsManyToMany, value); }
		}
		  
		[XmlAttribute("Path")]
		[Bindable(true)]
		public string Path 
		{
			get { return GetColumnValue<string>(Columns.Path); }
			set { SetColumnValue(Columns.Path, value); }
		}
		  
		[XmlAttribute("Depth")]
		[Bindable(true)]
		public int Depth 
		{
			get { return GetColumnValue<int>(Columns.Depth); }
			set { SetColumnValue(Columns.Depth, value); }
		}
		  
		[XmlAttribute("Roles")]
		[Bindable(true)]
		public string Roles 
		{
			get { return GetColumnValue<string>(Columns.Roles); }
			set { SetColumnValue(Columns.Roles, value); }
		}
		  
		[XmlAttribute("Flags")]
		[Bindable(true)]
		public int Flags 
		{
			get { return GetColumnValue<int>(Columns.Flags); }
			set { SetColumnValue(Columns.Flags, value); }
		}
		  
		[XmlAttribute("Description")]
		[Bindable(true)]
		public string Description 
		{
			get { return GetColumnValue<string>(Columns.Description); }
			set { SetColumnValue(Columns.Description, value); }
		}
		  
		[XmlAttribute("ExtendedProperties")]
		[Bindable(true)]
		public string ExtendedProperties 
		{
			get { return GetColumnValue<string>(Columns.ExtendedProperties); }
			set { SetColumnValue(Columns.ExtendedProperties, value); }
		}
		  
		[XmlAttribute("IsSystem")]
		[Bindable(true)]
		public bool IsSystem 
		{
			get { return GetColumnValue<bool>(Columns.IsSystem); }
			set { SetColumnValue(Columns.IsSystem, value); }
		}
		  
		[XmlAttribute("IsAbstract")]
		[Bindable(true)]
		public bool IsAbstract 
		{
			get { return GetColumnValue<bool>(Columns.IsAbstract); }
			set { SetColumnValue(Columns.IsAbstract, value); }
		}
		  
		[XmlAttribute("IsVersioned")]
		[Bindable(true)]
		public bool IsVersioned 
		{
			get { return GetColumnValue<bool>(Columns.IsVersioned); }
			set { SetColumnValue(Columns.IsVersioned, value); }
		}
		  
		[XmlAttribute("IsDeleted")]
		[Bindable(true)]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>(Columns.IsDeleted); }
			set { SetColumnValue(Columns.IsDeleted, value); }
		}
		  
		[XmlAttribute("IsAdmin")]
		[Bindable(true)]
		public bool IsAdmin 
		{
			get { return GetColumnValue<bool>(Columns.IsAdmin); }
			set { SetColumnValue(Columns.IsAdmin, value); }
		}
		
		#endregion
		
		
		#region PrimaryKey Methods		
		
        protected override void SetPrimaryKey(object oValue)
        {
            base.SetPrimaryKey(oValue);
            
            SetPKValues();
        }
        
		
		private Medianamik.Core.DAL.SubSonicDAL.TypeCollection colChildTypeRecords;
		public Medianamik.Core.DAL.SubSonicDAL.TypeCollection ChildTypeRecords()
		{
			if(colChildTypeRecords == null)
			{
				colChildTypeRecords = new Medianamik.Core.DAL.SubSonicDAL.TypeCollection().Where(Type.Columns.ParentTypeId, TypeId).Load();
				colChildTypeRecords.ListChanged += new ListChangedEventHandler(colChildTypeRecords_ListChanged);
			}
			return colChildTypeRecords;
		}
				
		void colChildTypeRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colChildTypeRecords[e.NewIndex].ParentTypeId = TypeId;
				colChildTypeRecords.ListChanged += new ListChangedEventHandler(colChildTypeRecords_ListChanged);
            }
		}
		private Medianamik.Core.DAL.SubSonicDAL.TypeInterfaceCollection colTypeInterfaceRecords;
		public Medianamik.Core.DAL.SubSonicDAL.TypeInterfaceCollection TypeInterfaceRecords()
		{
			if(colTypeInterfaceRecords == null)
			{
				colTypeInterfaceRecords = new Medianamik.Core.DAL.SubSonicDAL.TypeInterfaceCollection().Where(TypeInterface.Columns.TypeId, TypeId).Load();
				colTypeInterfaceRecords.ListChanged += new ListChangedEventHandler(colTypeInterfaceRecords_ListChanged);
			}
			return colTypeInterfaceRecords;
		}
				
		void colTypeInterfaceRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colTypeInterfaceRecords[e.NewIndex].TypeId = TypeId;
				colTypeInterfaceRecords.ListChanged += new ListChangedEventHandler(colTypeInterfaceRecords_ListChanged);
            }
		}
		private Medianamik.Core.DAL.SubSonicDAL.TypePermissionCollection colTypePermissionRecords;
		public Medianamik.Core.DAL.SubSonicDAL.TypePermissionCollection TypePermissionRecords()
		{
			if(colTypePermissionRecords == null)
			{
				colTypePermissionRecords = new Medianamik.Core.DAL.SubSonicDAL.TypePermissionCollection().Where(TypePermission.Columns.TypeId, TypeId).Load();
				colTypePermissionRecords.ListChanged += new ListChangedEventHandler(colTypePermissionRecords_ListChanged);
			}
			return colTypePermissionRecords;
		}
				
		void colTypePermissionRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colTypePermissionRecords[e.NewIndex].TypeId = TypeId;
				colTypePermissionRecords.ListChanged += new ListChangedEventHandler(colTypePermissionRecords_ListChanged);
            }
		}
		private Medianamik.Core.DAL.SubSonicDAL.TypeTemplateCollection colTypeTemplateRecords;
		public Medianamik.Core.DAL.SubSonicDAL.TypeTemplateCollection TypeTemplateRecords()
		{
			if(colTypeTemplateRecords == null)
			{
				colTypeTemplateRecords = new Medianamik.Core.DAL.SubSonicDAL.TypeTemplateCollection().Where(TypeTemplate.Columns.TypeId, TypeId).Load();
				colTypeTemplateRecords.ListChanged += new ListChangedEventHandler(colTypeTemplateRecords_ListChanged);
			}
			return colTypeTemplateRecords;
		}
				
		void colTypeTemplateRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colTypeTemplateRecords[e.NewIndex].TypeId = TypeId;
				colTypeTemplateRecords.ListChanged += new ListChangedEventHandler(colTypeTemplateRecords_ListChanged);
            }
		}
		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this Type
		/// 
		/// </summary>
		public Medianamik.Core.DAL.SubSonicDAL.Type ParentType
		{
			get { return Medianamik.Core.DAL.SubSonicDAL.Type.FetchByID(this.ParentTypeId); }
			set { SetColumnValue("ParentTypeId", value.TypeId); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varTypeId,Guid? varParentTypeId,string varName,bool varCanHaveChilds,bool varIsGenerated,bool varIsManyToMany,string varPath,int varDepth,string varRoles,int varFlags,string varDescription,string varExtendedProperties,bool varIsSystem,bool varIsAbstract,bool varIsVersioned,bool varIsDeleted,bool varIsAdmin)
		{
			Type item = new Type();
			
			item.TypeId = varTypeId;
			
			item.ParentTypeId = varParentTypeId;
			
			item.Name = varName;
			
			item.CanHaveChilds = varCanHaveChilds;
			
			item.IsGenerated = varIsGenerated;
			
			item.IsManyToMany = varIsManyToMany;
			
			item.Path = varPath;
			
			item.Depth = varDepth;
			
			item.Roles = varRoles;
			
			item.Flags = varFlags;
			
			item.Description = varDescription;
			
			item.ExtendedProperties = varExtendedProperties;
			
			item.IsSystem = varIsSystem;
			
			item.IsAbstract = varIsAbstract;
			
			item.IsVersioned = varIsVersioned;
			
			item.IsDeleted = varIsDeleted;
			
			item.IsAdmin = varIsAdmin;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varTypeId,Guid? varParentTypeId,string varName,bool varCanHaveChilds,bool varIsGenerated,bool varIsManyToMany,string varPath,int varDepth,string varRoles,int varFlags,string varDescription,string varExtendedProperties,bool varIsSystem,bool varIsAbstract,bool varIsVersioned,bool varIsDeleted,bool varIsAdmin)
		{
			Type item = new Type();
			
				item.TypeId = varTypeId;
			
				item.ParentTypeId = varParentTypeId;
			
				item.Name = varName;
			
				item.CanHaveChilds = varCanHaveChilds;
			
				item.IsGenerated = varIsGenerated;
			
				item.IsManyToMany = varIsManyToMany;
			
				item.Path = varPath;
			
				item.Depth = varDepth;
			
				item.Roles = varRoles;
			
				item.Flags = varFlags;
			
				item.Description = varDescription;
			
				item.ExtendedProperties = varExtendedProperties;
			
				item.IsSystem = varIsSystem;
			
				item.IsAbstract = varIsAbstract;
			
				item.IsVersioned = varIsVersioned;
			
				item.IsDeleted = varIsDeleted;
			
				item.IsAdmin = varIsAdmin;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn TypeIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ParentTypeIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn CanHaveChildsColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn IsGeneratedColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn IsManyToManyColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn PathColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn DepthColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn RolesColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn FlagsColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn DescriptionColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn ExtendedPropertiesColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn IsSystemColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        public static TableSchema.TableColumn IsAbstractColumn
        {
            get { return Schema.Columns[13]; }
        }
        
        
        
        public static TableSchema.TableColumn IsVersionedColumn
        {
            get { return Schema.Columns[14]; }
        }
        
        
        
        public static TableSchema.TableColumn IsDeletedColumn
        {
            get { return Schema.Columns[15]; }
        }
        
        
        
        public static TableSchema.TableColumn IsAdminColumn
        {
            get { return Schema.Columns[16]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string TypeId = @"TypeId";
			 public static string ParentTypeId = @"ParentTypeId";
			 public static string Name = @"Name";
			 public static string CanHaveChilds = @"CanHaveChilds";
			 public static string IsGenerated = @"IsGenerated";
			 public static string IsManyToMany = @"IsManyToMany";
			 public static string Path = @"Path";
			 public static string Depth = @"Depth";
			 public static string Roles = @"Roles";
			 public static string Flags = @"Flags";
			 public static string Description = @"Description";
			 public static string ExtendedProperties = @"ExtendedProperties";
			 public static string IsSystem = @"IsSystem";
			 public static string IsAbstract = @"IsAbstract";
			 public static string IsVersioned = @"IsVersioned";
			 public static string IsDeleted = @"IsDeleted";
			 public static string IsAdmin = @"IsAdmin";
						
		}
		#endregion
		
		#region Update PK Collections
		
        public void SetPKValues()
        {
                if (colChildTypeRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.Type item in colChildTypeRecords)
                    {
                        if (item.ParentTypeId != TypeId)
                        {
                            item.ParentTypeId = TypeId;
                        }
                    }
               }
		
                if (colTypeInterfaceRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.TypeInterface item in colTypeInterfaceRecords)
                    {
                        if (item.TypeId != TypeId)
                        {
                            item.TypeId = TypeId;
                        }
                    }
               }
		
                if (colTypePermissionRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.TypePermission item in colTypePermissionRecords)
                    {
                        if (item.TypeId != TypeId)
                        {
                            item.TypeId = TypeId;
                        }
                    }
               }
		
                if (colTypeTemplateRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.TypeTemplate item in colTypeTemplateRecords)
                    {
                        if (item.TypeId != TypeId)
                        {
                            item.TypeId = TypeId;
                        }
                    }
               }
		}
        #endregion
    
        #region Deep Save
		
        public void DeepSave()
        {
            Save();
            
                if (colChildTypeRecords != null)
                {
                    colChildTypeRecords.SaveAll();
               }
		
                if (colTypeInterfaceRecords != null)
                {
                    colTypeInterfaceRecords.SaveAll();
               }
		
                if (colTypePermissionRecords != null)
                {
                    colTypePermissionRecords.SaveAll();
               }
		
                if (colTypeTemplateRecords != null)
                {
                    colTypeTemplateRecords.SaveAll();
               }
		}
        #endregion
	}
}
